/*
 * Copyright (c) 2015, the DeltaSync# project. All Rights Reserved.
 * This project is a C# port of the JDeltaSync project:
 *     http://jdeltasync.googlecode.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using System.Net;
using System.Text;

/**
 * Represents a particular user's session.
 */
public class DeltaSyncSession {
    private NetworkCredential 
                    credential;
    private string  ticket;
    private Uri     baseUri;
    /*private CookieContainer 
                    cookies;*/
    
    /**
     * Creates a new {@link DeltaSyncSession}.
     * 
     * @param username the user's username.
     * @param password the user's password.
     */
    public DeltaSyncSession(NetworkCredential credential, string ticket/*, CookieContainer cookies = null*/) {
        if (credential == null)
            throw new ArgumentNullException("Credentials");
        if (string.IsNullOrEmpty(ticket))
            throw new ArgumentNullException("SecurityTicket");
        this.credential = credential;
        this.ticket     = ticket;
      //this.cookies    = cookies;
    }

    /**
     * Returns the session Credentials.
     * 
     * @return the session Credentials.
     */
    public NetworkCredential Credential {
        get { return credential; }
    }


    /**
     * Returns the ticket associated with this session. This is what the login
     * process returns and the ticket has to be used in every subsequent
     * <code>Sync</code>, <code>ItemOperations</code>, etc request to the 
     * server.
     * 
     * @return the ticket.
     */
    public string Ticket {
        get { return ticket;  }
    }
    
    /**
     * Returns the BaseUri.
     * 
     * @return the BaseUri.
     */
    public Uri BaseUri {
        get { return baseUri;  }
        set { baseUri = value; }
    }
        
    /**
     * Returns the Cookies.
     * 
     * @return the Cookies.
     */
    /*public CookieContainer Cookie {
        get { return cookies; }
    }*/
    
    public override string ToString() {
        StringBuilder sb = new StringBuilder(base.ToString() + "(");
        sb.Append("username").Append("=").Append(credential.UserName).Append(",");
        sb.Append("password").Append("=").Append("******").Append(",");
        sb.Append("ticket")  .Append("=").Append(ticket);
        sb.Append(")");
        return sb.ToString();
    }
}
